import os
import time

class DebugObj:

    class __impl:

        def __init__(self):
            self.filename = 'debug.txt'

        def clear(self):
            open(self.filename, 'w')

        def write(self, msg):
            msg = time.ctime() + ": " + msg
            print(msg)
            open(self.filename, 'a').write(msg + '\n')

    # storage for the instance reference
    __instance = None

    def __init__(self):
        """ Create singleton instance """
        # Check whether we already have an instance
        if DebugObj.__instance is None:
            # Create and remember instance
            DebugObj.__instance = DebugObj.__impl()

        # Store instance reference as the only member in the handle
        self.__dict__['_DebugObj__instance'] = DebugObj.__instance

    def __getattr__(self, attr):
        """ Delegate access to implementation """
        return getattr(self.__instance, attr)

    def __setattr__(self, attr, value):
        """ Delegate access to implementation """
        return setattr(self.__instance, attr, value)
